package com.six.goods.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.six.core.entity.Category;
import com.six.core.entity.Spec;
import com.six.core.vo.Result;
import com.six.goods.mapper.SpecMapper;
import com.six.goods.service.SpecService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author wang
* @description 针对表【sto_spec】的数据库操作Service实现
* @createDate 2023-02-27 15:20:16
*/
@Service
public class SpecServiceImpl extends ServiceImpl<SpecMapper, Spec>implements SpecService {
    @Autowired
    private SpecMapper specMapper;
    //规格--分页
    @Override
    public Result seleAllSpec(Integer currentPage, Integer pageSize, Spec spec) {
        PageHelper.startPage(currentPage, pageSize);
        List<Spec> specs = specMapper.selectSpec(spec);
        PageInfo<Spec> pageInfo = new PageInfo<>(specs);
        if (pageInfo != null) {
            return new Result(2000, "规格-查询成功", pageInfo);
        } else {
            return new Result(5000, "规格-查询失败");
        }
    }
    //规格--添加
    @Override
    public Result insertSpec(Spec spec) {
        int i = specMapper.insert(spec);
        if (i>0){
            return new Result(2000,"规格-添加成功");
        }else {
            return new Result(5000,"规格-添加失败");
        }
    }
    //规格--删除
    @Override
    public Result deleteSpec(Integer id) {
        int i = specMapper.deleteById(id);
        if (i>0){
            return new Result(2000,"规格-删除成功");
        }else {
            return new Result(5000,"规格-删除失败");
        }
    }
    //规格--修改
    @Override
    public Result updateSpec(Spec spec) {
        int i = specMapper.updateById(spec);
        if (i>0){
            return new Result(2000,"规格-修改成功");
        }else {
            return new Result(5000,"规格-修改失败");
        }
    }

    @Override
    public Result selectAllSpec() {
        List<Spec> specs = specMapper.selectSpec(null);
        if (specs!=null){
            return new Result(2000,"查询成功",specs);
        }else {
            return new Result(5000,"查询失败");
        }
    }
}




